package com.example.forjava.aspect;

import com.example.forjava.controller.AopController;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/*@Aspect
@Component
@Order(0)*/
public class PermissionFirstAdvice {

    // 定义一个切面，括号内写入第1步中自定义注解的路径
    @Pointcut("@annotation(com.example.forjava.annotation.PermissionAnnotation)")
    private void permissionCheck() {
    }

    @Before("permissionCheck()")
    public void beforeAdvice(JoinPoint joinPoint){
        System.out.println("before");
    }


    @Around("permissionCheck()")
    public Object permissionCheckFirst(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("===================第一个切面===================：" + System.currentTimeMillis());
        //获取请求参数，详见接口类
        AopController.User args = (AopController.User) joinPoint.getArgs()[0];
        System.out.println(args.getName());
        return joinPoint.proceed();
    }

    @After("permissionCheck()")
    public void afterAdvice(JoinPoint joinPoint){
        System.out.println("after");
    }

    @AfterReturning(value = "permissionCheck()",returning = "value")
    public void afterReturning(JoinPoint joinPoint, String value){
        System.out.println("afterReturning:"+value);
    }

    @AfterThrowing(value = "permissionCheck()",throwing = "e")
    public void afterThrowing(JoinPoint joinPoint,Exception e){
        System.out.println("afterThrowing:"+e);
    }


}
